//index.js
//获取应用实例

import {ajax} from "../../utils/httpRequest.js";

Page({
  data: {
    pageData: []
  },
  onLoad: function () {
    this.initData();
  },
  initData() {
    ajax.get('https://api.cloudcpc.com/index.php/home/Applets/getindex', {}, {}, res => {
      this.setData({pageData: res.data});
      console.log(this.data.pageData);
    })
  },
  swiperClick(e) {
    let params = e.currentTarget.dataset;
    //console.log(params);
    ajax.post('https://api.cloudcpc.com/index.php/home/Applets/get_recording', {
      appid: params.id
    }, {}, res => {
      wx.navigateToMiniProgram({
        appId: params.appid,
        path: params.path ||'pages/entry/authorize/authorize',
        //path: 'pages/index/index',
        extraData: {},
        envVersion: 'release',
        success(res) {
          // 打开成功
          console.log(res);
        },
        fail(error) {
          console.log(error);
        }
      })
    })
  },
  jumpTo(e) {
    let params = e.currentTarget.dataset;
    // console.log(params);
    ajax.post('https://api.cloudcpc.com/index.php/home/Applets/get_recording', {
      appid: params.id
    }, {}, res => {
      wx.navigateToMiniProgram({
        appId: params.appid,
        path: params.path ||'pages/entry/authorize/authorize',
        //path: 'pages/index/index',
        extraData: {},
        envVersion: 'release',
        success(res) {
          // 打开成功
          console.log(res);
        },
        fail(error) {
          console.log(error);
        }
      })
    })
  },
  // toOnlineTest(e) {
  //   console.log(e.currentTarget.dataset);
  //   if (e.currentTarget.dataset.title == '在线考试') {
  //     wx.navigateToMiniProgram({
  //       appId: 'wx00559721ae0d4752',
  //       path: 'pages/index/index',
  //       extraData: {},
  //       envVersion: 'release',
  //       success(res) {
  //         // 打开成功
  //       },
  //       fail(error) {
  //         console.log(error);
  //       }
  //     })
  //   }
  // }
});
